package com.ncepu.clubmanagement.mapper;

import com.ncepu.clubmanagement.pojo.Message;
import com.ncepu.clubmanagement.pojo.MessageLink;
import com.ncepu.clubmanagement.pojo.MessageMetaData;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("insert into message( message_content, message_title, target_club_id, source_person_id, send_type) " +
            "values (#{messageContent}, #{messageTitle}, #{targetClubId}, #{sourcePersonId}, #{sendType})")
    @Options(useGeneratedKeys = true, keyProperty = "messageId", keyColumn = "message_id")
    public void insertMessage(Message message);

    void insertMessageLinks(List<MessageLink> links);

    List<MessageMetaData> selectMessageMetaDataByTargetPersonId(Integer targetPersonId);

    @Update("update message_link set is_read = 1 where message_id = #{messageId} and target_person_id = #{personId}")
    void setMessageIsReadByMessageIdAndPersonId(Integer messageId, Integer personId);

    String getMessageContentByMessageIdAndPersonId(Integer messageId, Integer targetPersonId);
}
